﻿using System;
using System.Diagnostics;
using System.IO;

namespace WindowsWeb
{

    /// <summary>
    /// 写日志
    /// </summary>
    public class LogHelper
    {
        /// <summary>
        /// 异常退出超时时间，单位秒
        /// </summary>
        public const int LogoutTime = 60;
        private string rootFileName = AppDomain.CurrentDomain.BaseDirectory + @"Log\";
        private LogHelper()
        {
            if (System.IO.Directory.Exists(rootFileName) == false)//如果不存在文件夹则创建 
            {
                System.IO.Directory.CreateDirectory(rootFileName);
            }
        }

        private static LogHelper _Current;
        public static LogHelper Current
        {
            get
            {
                if (_Current == null)
                {
                    _Current = new LogHelper();
                }
                return _Current;
            }
        }

        /// <summary>
        /// 操作正常写日志
        /// </summary>
        /// <param name="message"></param>
        public void WriteIPString(string IP)
        {
            string fileName = string.Empty;
            fileName = rootFileName + "InfIP.Log";
            try
            {
                StreamWriter sw;
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                    sw = File.CreateText(fileName);
                }
                else
                {
                    sw = File.CreateText(fileName);
                }
                sw.Write(IP);
                sw.Close();
            }
            catch
            { }
        }

        public string ReadIPString()
        {
            string fileName = string.Empty;
            fileName = rootFileName + "InfIP.Log";
            string ip = string.Empty;
            try
            {
                if (File.Exists(fileName))
                {
                   ip = File.ReadAllText(fileName);
                }
            }
            catch (System.Exception ex)
            {
            	
            }
            return ip;
        }
    }
}